<?php
/**
 * DCRM Mobile Page
 *
 * This file is part of WEIPDCRM.
 * 
 * WEIPDCRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WEIPDCRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with WEIPDCRM.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('system/common.inc.php');

base_url();

// URL For Rewrite 
$rewrite_mod = get_option('rewrite_mod');
switch($rewrite_mod){
	case 3:
		$rewrite_url = array('view' => 'view/%d', 'view_nohistory' => 'view/%d/nohistory', 'screenshot' => 'screenshot/%d', 'history' => 'history/%d', 'contact' => 'contact/%d', 'section' => 'section/%d', 'report' => 'report/%d', 'report_support' => 'report/%1$d/%2$d', 'more' => 'more/%d', 'more_offset' => 'more/%1$d/%2$d', 'misc' => 'misc');
		break;
	case 1:
	case 2:
	default:
		$rewrite_url = array('view' => 'index.php?method=view&amp;pid=%d', 'view_nohistory' => 'index.php?pid=%d&amp;addr=nohistory', 'screenshot' => 'index.php?method=screenshot&amp;pid=%d', 'history' => 'index.php?method=history&amp;pid=%d', 'contact' => 'index.php?method=contact&amp;pid=%d', 'section' => 'index.php?method=section&amp;pid=%d', 'report' => 'index.php?method=report&amp;pid=%d', 'report_support' => 'index.php?method=report&amp;pid=%1$d&amp;support=%2$d', 'more' => 'index.php?method=more&amp;pid=%d', 'more_offset' => 'index.php?method=more&amp;pid=%1$d&amp;offset=%2$d', 'misc' => 'misc.php');
		break;
}
function echo_rewrite_url($type, $variable1, $variable2=''){
	global $rewrite_url;
	echo SITE_URL;
	printf($rewrite_url[$type], $variable1, $variable2);
}

class_loader('Mobile_Detect');
$detect = new Mobile_Detect;
if(!$detect->isiOS()){
	if (DCRM_PCINDEX == 1) {
		header("Location: ".SITE_URL."User.php");
		exit();
	} else {
		$isCydia = false;
	}
} else {
	if (DCRM_MOBILE == 2) {
		if (!strpos($detect->getUserAgent(), 'Cydia')) {
			$isCydia = false;
		} else {
			$isCydia = true;
		}
	} else {
		exit('Access Denied');
	}
}
if (file_exists('Release')) {
	$release = file('Release');
	$release_origin = __('No Name');
	$release_mtime = filemtime('Release');
	$release_time = date('Y-m-d H:i:s',$release_mtime);
	foreach ($release as $line) {
		if(preg_match('#^Origin#', $line)) {
			$release_origin = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
		if(preg_match("#^Description#", $line)) {
			$release_description = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
	}
} else {
	$release_origin = __('Empty Page');
}
if (isset($_GET['pid'])) {
	if (ctype_digit($_GET['pid']) && intval($_GET['pid']) <= 10000) {
		function device_check(){
			global $detect;
			$device_type = array('iPhone', 'iPod', 'iPad');
			for ($i = 0; $i < count($device_type); $i++) {
				$check = $detect->version($device_type[$i]);
				if ($check !== false) {
					if (isset($_SERVER['HTTP_X_MACHINE'])) {
						$DEVICE = $_SERVER['HTTP_X_MACHINE'];
					} else {
						$DEVICE = 'Unknown';
					}
					$OS = str_replace('_', '.', $check);
					break;
				}
			}
			return array('DEVICE' => $DEVICE, 'OS' => $OS);
		}

		if (isset($_GET['method']) && $_GET['method'] == 'screenshot') {
			$index = 2;
			$title = __('View Screenshots');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'report') {
			$device_info = device_check();
			if (!isset($_GET['support'])) {
				$index = 3;
			} else {
				if ($_GET['support'] == '1') {
					$support = 1;
				} elseif ($_GET['support'] == '2') {
					$support = 2;
				} elseif ($_GET['support'] == '3') {
					$support = 3;
				} else {
					$support = 0;
				}
				$index = 4;
			}
			$title = __('Report Problems');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'history') {
			$index = 5;
			$title = __('Version History');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'contact') {
			$index = 6;
			$title = __('Contact us');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'pcsection') {
			$index = 7;
          $section = DB::fetch_first("SELECT `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections` WHERE `ID` = '".(int)$_GET['pid']."'");
			$title = __(DB::real_escape_string($section['Name']));
		} elseif (isset($_GET['method']) && $_GET['method'] == 'more') {
			$index = 8;
			$section = DB::fetch_first("SELECT `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections` WHERE `ID` = '".(int)$_GET['pid']."'");
			$q_name = DB::real_escape_string($section['Name']);
			if (isset($_GET['offset']) && !empty($_GET['offset']) && ctype_digit($_GET['offset'])) {
				$offset = intval($_GET['offset']);
			} else {
				$offset = 0;
			}
			$packages = DB::fetch_all("SELECT `ID`, `Name`, `Package` FROM `".DCRM_CON_PREFIX."Packages` WHERE (`Stat` = '1' AND `Section` = '".$q_name."') ORDER BY `ID` DESC LIMIT 10 OFFSET ".$offset);
			foreach($packages as $package){
				if(!empty($package)){
					if ($isCydia) { ?>
				<a href="cydia://package/<?php echo($package['Package']); ?>" target="_blank">
<?php					} else { ?>
				<li>
	<a href="<?php echo_rewrite_url('pc', $package['ID']);?>" class="app_icon" >
<?php					} ?>
	
    
<div class="desc" ><?php echo ($package['Description']);  ?></div>
</li>
<?php
				}
			}
			exit();
		} elseif (!isset($_GET['method']) || (isset($_GET['method']) && $_GET['method'] == 'public')) {
			$index = 1;
			$title = __('View Package');
			$package_id = (int)DB::real_escape_string($_GET['pid']);
			$package_info = DB::fetch_first("SELECT `Name`, `Version`, `Author`, `Package`, `Description`, `DownloadTimes`, `Multi`, `CreateStamp`, `Size`, `Installed-Size`, `Section`, `Homepage`, `Tag`, `Level`, `Price`, `Purchase_Link`, `Changelog`, `Changelog_Older_Shows`, `Video_Preview`, `System_Support`, `ScreenShots` FROM `".DCRM_CON_PREFIX."Packages` WHERE `ID` = '".$package_id."' LIMIT 1");
			if ($package_info) $title = $package_info['Name'];
		} else {
			httpinfo(405);
			exit();
		}
	} else {
		httpinfo(405);
		exit();
	}
} elseif (!isset($_GET['method'])) {
	$index = 0;
	$title = $release_origin;
} else {
	httpinfo(405);
	exit();
}
?>
 <style>
/* reset webkit search input browser style */
input {
	outline: none;
}
input[type=search] {
	-webkit-appearance: textfield;
	-webkit-box-sizing: content-box;
	font-family: inherit;
	font-size: 100%;
}
input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
	display: none; /* remove the search and cancel icon */
}

/* search input field */
input[type=search] {
	/*background: #ededed url(./Cydia/search-icon.png) no-repeat 9px center;*/
	border: solid 1px #ccc;
	padding: 9px 10px 9px 32px;
	width: 85%;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
}
   
input[type=search2]:focus {
	width: 70%;
	background-color: #fff;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
}
input[type=search2] {
	/*background: #ededed url(./Cydia/search-icon.png) no-repeat 9px center;*/
	border: solid 1px #ccc;
	padding: 9px 10px 9px 32px;
	width: 75%;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
}
input[type=search]:focus {
	width: 70%;
	background-color: #fff;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
}
/* placeholder */
input:-moz-placeholder {
	color: #999;
}
input::-webkit-input-placeholder {
	color: #999;
}
button {
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  text-shadow: 0px 1px 0px #2f6627;
  color: #ffffff;
height: 40px;
  width: 80%;
  background: #44c767;

  border: solid #18ab29 1px;
  text-decoration: none;
}
   
button[type=button] {
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  text-shadow: 0px 1px 0px #2f6627;
  color: #ffffff;
height: 35px;
  width: 22%;
  background: #44c767;

  border: solid #18ab29 1px;
  text-decoration: none;
}
button[type=button2] {
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  text-shadow: 0px 1px 0px #2f6627;
  color: #ffffff;
height: 35px;
  width: 80%;
  background: #44c767;

  border: solid #18ab29 1px;
  text-decoration: none;
}   
button:hover {
  color: #ffffff;
  background: #5cbf2a;
  text-decoration: none;
}

</style>                 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>会员个人中心</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="apple-mobile-web-app-title" content="<?php echo($release_origin); ?>" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
		<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="robots" content="index, follow" />
		<link rel="stylesheet" href="./Cydia/menes2.min.css">
      <link rel="stylesheet" href="<?php echo(SITE_URL); ?>/ziyuan/boot.css">
		<link rel="stylesheet" href="./Cydia/scroll2.min.css">     
		<script src="./Cydia/user/fastclick.js" type="text/javascript"></script>
		<script src="./Cydia/user/menes.js" type="text/javascript"></script>
		<script src="./Cydia/user/cytyle.js" type="text/javascript"></script><!--<base target="_top">--><base href="." target="_top"><style type="text/css"> p, input[type="password"], input[type="text"], select { top: 0.051470588235294115em; } </style>
		<script src="./Cydia/user/jquery.min.js"></script>
 <?php
if (defined("AUTOFILL_SEO")) {
?>
		<meta name="title" content="<?php echo(AUTOFILL_SEO); ?>" />
<?php
}
if (!empty($release_description)) {
?>
		<meta name="description" content="<?php echo($title); ?> ™| 最简洁的中文源，简单整洁有序的Cydia源，提供实用的DEB包。" />
<?php
}
if (defined("AUTOFILL_KEYWORDS")) {
?>
		<meta name ="keywords" content="<?php echo(AUTOFILL_KEYWORDS); ?>" />
<?php
}
if ($isCydia) {
?>
		<base target="_blank">
<?php
} else {
?>
		<base target="_top">
<?php
}
?>  

</head>
  
	<body class="pinstripe">
            <panel>
     <div style="height:2px;width:100%">
        <div style="background-color:red;height:2px;width:0" id="progress"></div>
    </div>
    <panel class="left">
        <div style="margin:9px;padding:0 16px">
            <style type="text/css">
                .cytyle-flat #logo {
                    background-image: url("./CydiaIcon.png");
                    background-size: 58px 58px;
                    width: 58px
                }
            </style>        
            <div id="logo" style="position:absolute;display:inline-block;height:58px;vertical-align:middle" alt="Cydia Logo"></div>
            <p style="padding-top:8px;margin-left:70px;text-align:center;display:block;height:60px;text-rendering:optimizeLegibility">
            <span style="font-size:18px">欢迎使用 Cydia 帐户<sup>™</sup></span><br>
            <span style="font-size:14px"><a>会员个人管理中心</a></span><br>
            <span style="font-size:14px"><a>Build by <?php echo(AUTOFILL_SEO); ?></a></span></p>
        </div>

      
<?php
require_once 'qqlogin/function.php';
require_once 'qqlogin/Connect2.1/qqConnectAPI.php';
?>     
      
<?php if(!isset($_SESSION['accesstoken']) || !isset($_SESSION['openid'])) { ?>
     <block>
        <p style="color: #303130; font-size:14px;">欢迎使用<?php echo(AUTOFILL_SEO); ?>会员权限升级！请登录！</p>  
    </block>
      <fieldset class="box">
                  <a href="./qqlogin/qqlogin.php" target="_self"> 
                        <img class="icon" src="./icon/default/qqlogin.png">
                            <div>
                                <div>
                                    <label>
                                        <p>使用 QQ 授权登录</p>
                                    </label>
                                </div>
                            </div>
                  </a>
        </fieldset>
<?php } else { 
   
$qc = new QC($_SESSION['accesstoken'],$_SESSION['openid']);
$arr = $qc->get_user_info();
             
?>
<?php 
if(isset($_SESSION["accesstoken"]) || isset($_SESSION["openid"])) {      
$User=$arr["nickname"];
$Logo=$arr['figureurl_qq_2'];
$Openid=$_SESSION["openid"];
$date=date("Y-m-d h:i:s");
$ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];   
if($row=DB::result_first("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `Openid`='".$Openid."'" )){    
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."User` SET `Logo` = '".$Logo."', `User` = '".$User."',`IP` = '".$ip."' WHERE `Openid`='".$Openid."'");
} else {  
  $query = DB::query("INSERT INTO `".DCRM_CON_PREFIX."User` (ID,User,Logo,Openid,Packages,Collection,TimeStamp,IP) VALUES ('','$User','$Logo','$Openid','','','$date','$ip')");
}      
}
?>       
<?php
$UDID =  $_GET['UDID'] ? $_GET['UDID'] : $_POST['UDID'];
$PRODUCT =  $_GET['PRODUCT'] ? $_GET['PRODUCT'] : $_POST['PRODUCT'];
?>	      
     <block class="box1" style="background-color: #FFFFFF;">
        <p style="color: #303130; font-size:14px;">欢迎使用<?php echo(AUTOFILL_SEO); ?>软件</p>  

     <center><span class="btn"><p>会员权限升级</p></span></center>
        </block>
    		<fieldset class="box">
                  <a>
                        <img class="icon" src="<?php echo $arr['figureurl_qq_2'];?>" style="border-radius: 50%;box-shadow:0 0 1px #AAA;padding:1px;margin-right: 1px;">
                            <div>
                                <div>
                                      <label>
                                        <p>用户名：<?php echo $arr["nickname"];?></p><i onclick="cookipost()" class="ui-btn3" style="color: #979797; float:right;">返回</i>
                                    </label>
                                </div>
                            </div>
                  </a>
 <?php
   if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID`='".$_SESSION['openid']."' ORDER BY `Level` DESC limit 1" )){      
   ?>
<?php
          $ress = DB::query("SELECT `Level`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `Openid`='".$_SESSION['openid']."'ORDER BY `Level` DESC limit 1");
		foreach($ress as $res){       
?>   
 <?php
function diffBetweenTwoDays ($day1, $day2)
{
  $second1 = strtotime($day1);
  $second2 = strtotime($day2);
    
  if ($second1 < $second2) {
    $tmp = $second2;
    $second2 = $second1;
    $second1 = $tmp;
  }
  return ($second1 - $second2) / 86400;
}
$time = strtotime($res['CreateStamp']);
$date=date("Y-m-d"); 
$day1 = $date;
$day2 = (date("Y-m-d", $time));
$diff = diffBetweenTwoDays($day1, $day2);                            
?>               
                  <a>
                        <img class="icon" src="<?php echo(SITE_URL); ?>icon/<?php 
                         if($res['Level']=='2'){ echo 'lv1.png';}
                         if($res['Level']=='3'){echo 'lv2.png';}  
                         if($res['Level']=='4'){echo 'lv3.png';}       
                         if($res['Level']=='5'){echo 'lv4.png';}      
                         if($res['Level']=='6'){echo 'lv5.png';}       
                         if($res['Level']=='7'){echo 'lv6.png';}
                                               ?>" style="border-radius: 50%;box-shadow:0 0 1px #AAA;padding:1px;margin-right: 1px;">
                            <div>
                                <div>
                                      <label>
                                        <p>当前等级：
                                          <?php 
                    if($res['Level']=='2'){ echo '蓝苹果会员';}
                    if($res['Level']=='3'){echo '铜苹果会员';}  
                    if($res['Level']=='4'){echo '银苹果会员';}       
                    if($res['Level']=='5'){echo '金苹果会员';}      
                    if($res['Level']=='6'){echo '白金尊贵会员';}       
                    if($res['Level']=='7'){echo '系统管理员';}      
                                          ?></p>
                                    </label>
                                </div>
                          </div> 
                    </a>
       <div>
        <p  style="text-align:left">◉今日是您加入会员第<?php echo($diff); ?>天！</p>   
      </div>  
<?php
 }
 } else {
?>            
                    <a>
                        <img class="icon" src="<?php echo(SITE_URL); ?>icon/gly.png" style="border-radius: 50%;box-shadow:0 0 1px #AAA;padding:1px;margin-right: 1px;">
                            <div>
                                <div>
                                      <label>
                                        <p>当前等级：小苹果会员</p>
                                    </label>
                                </div>
                          </div> 
                    </a>   
<?php  
 }
?>            
<?php                        
		if (DCRM_DIRECT_DOW4 == 2) {
?>
                  <a> 
                        <img class="icon" src="./icon/user.png">
                            <div>
                                <div>
                                    <label>
                                        <p>购买会员组</p><i onclick="cookipost2()" class="ui-btn3" style="color: #979797; float:right;">购买</i>
                                    </label>
                                </div>
                            </div>
                  </a>  
              
  <script language="javascript">
    function cookipost2(){
    	parent.location.href='<?php echo(htmlspecialchars(AUTOFILL_GOUMAICUSTOM)); ?>'; 
	}
  </script>          
              
<?php
        }                        
		if (DCRM_DIRECT_DOW4 == 1) {
?>
                  <a> 
                        <img class="icon" src="./icon/user.png">
                            <div>
                                <div>
                                    <label>
                                        <p>购买会员组</p><i onclick="cookipost2()" class="ui-btn3" style="color: #979797; float:right;">购买</i>
                                    </label>
                                </div>
                            </div>
                  </a>
              
  <script language="javascript">
    function cookipost2(){
    	alert('管理员未设置购买链接') 
	}
  </script>      
            
<?php
        }
?>               
                  </fieldset>
  <script language="javascript">
    function cookipost(){
    	parent.location.href='favourite.php'; 
	}
  </script>       
      
      

<?php
  if ($isCydia) {
?>
<?php
  if ($_SESSION["UDID"]=="") {
?> 
      
<script src="<?php echo(SITE_URL); ?>js/2_clipboard.min.js" type="text/javascript"></script>
<br><center><button type='button2' id='button' ><i></i>复制地址前往自带浏览器升级</button></center><br> 
<script type="text/javascript">
            var clipboard = new Clipboard('button', {
                text: function() {
                    return "http:<?php echo(SITE_URL); ?>userjh.php";
                }
            });
            clipboard.on('success', function(e) {
                alert('复制成功！请前往手机自带浏览器中打开并粘贴网址');
            });
            clipboard.on('error', function(e) {
               alert('复制失败！您的系统版本不兼容复制功能！\n请手动前往自带浏览器打开该地址\nhttp:<?php echo(SITE_URL); ?>/userjh.php');
               
            });
</script>     
<?php
  } else {
?>
<form action="" method="get">
<center><span class="btn"><input disabled type="search" name="udid" minlength="40" maxlength="40" data-validation-regex-regex="[a-zA-Z0-9]*" data-validation-minlength-message="<?php _e('UDID必须是40个字符！'); ?>" data-validation-maxlength-message="<?php _e('UDID必须是40个字符！'); ?>" data-validation-regex-message="<?php _e('UDID must be number or letter!!'); ?>"  value="<?php echo $_SESSION["UDID"];?>" placeholder="请点击获取UDID" ></span></center><br>  
<p class="help-block"></p>
  <center><span class="btn"><input  type="search" name="Activation" value="" placeholder="请输入您的激活码" ></span></center><br>
<center><button type="submit" ><i></i>激活用户组</button></center>
</form> <br>
<?php
  }
?>       

<?php
  } else {
?>
<div id="weixin" style="display:none">
    <div class="click_opacity"></div>
    <div class="to_btn">
    	<span class="span1"><img src="<?php echo(SITE_URL); ?>/click_btn.png"></span>
        <span class="span2"><em>1</em> 点击右上角<img src="<?php echo(SITE_URL); ?>/menu.png">打开菜单</span>
        <span class="span2"><em>2</em> 选择<img src="<?php echo(AUTOFILL_SITE); ?>/safari.png">用Safari打开下载</span>
    </div>
</div>
<script>
$(function(){
$(document).on('click','#ios9tip', function () {
  $.popup('.popup-about');
});
$(document).on('click','#cra_tip', function () {
  $.popup('.popup-about2');
});
$(document).on('click','#cra_tip1', function () {
  $.popup('.popup-about3');
});
function is_ios9() {
	if((navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i))) {
		return Boolean(navigator.userAgent.match(/OS [9-9]_\d[_\d]* like Mac OS X/i));
	} else {
		return false;
	}
}

function is_weixin(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.match(/MicroMessenger/i)=="micromessenger") {
		return true;
	} else {
		return false;
	}
}
function show(titles,texts){
    $.modal({
	  title:  titles,
      text: texts,
      buttons: [
        {
          text: '我知道了',
          bold: true
        },
      ]
    })
}

$(document).on("click","#down",function(){
	var browser = {
		versions: function() {
			var u = navigator.userAgent, app = navigator.appVersion;
			return {
				trident: u.indexOf('Trident') > -1,
				presto: u.indexOf('Presto') > -1,
				webKit: u.indexOf('AppleWebKit') > -1,
				gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
				mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
				ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
				android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
				iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
				iPad: u.indexOf('iPad') > -1,
				webApp: u.indexOf('Safari') == -1
			};
		}()
	}
	if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
		//微信打开时 系统为ios
		if(is_weixin()){
			$('#weixin').show();
			return ;
		} else {
			//系统为ios  不是微信打开
			if(is_ios9()){
				//ios9提示
				$('#ios9tip').show();
			}
		}
	} else {
		//弹出提示不是 ios 设备
		$('#down').hide();
		$('#down_tip').html("当前程序只支持苹果IOS设备");
		$('#down_tip').show();
		show("非常抱歉","当前程序只支持苹果IOS设备。");
		return ;
	}
	//下载
	window.location.href = 'https:<?php echo(SITE_URL); ?>udid.mobileconfig';
	$.showPreloader();
	setTimeout(function () {
		$('#install_tips').show();
		$('#cra_tip').show();
		$('#cra_tip1').show();
		$('#down').hide();
		$.hidePreloader();
	}, 2000);
});
})
</script>      
     <block class="box1" style="background-color: #FFFFFF;">
        <p style="color: #FF0000; font-size:14px;">请先点击下方绿色的<strong style="color: #44c767; font-size:16px;">获取UDID</strong><br><p style="color: #FF0000; font-size:14px;">获取您手机的UDID！再进行输入激活码！激活<br>请勿乱输入UDID否则造成激活失败无法下载概不负责</p>
    </block>      
<form action="" method="get">
<center><span class="btn"><input type="search2" name="udid" minlength="40" maxlength="40" data-validation-regex-regex="[a-zA-Z0-9]*" data-validation-minlength-message="<?php _e('UDID必须是40个字符！'); ?>" data-validation-maxlength-message="<?php _e('UDID必须是40个字符！'); ?>" data-validation-regex-message="<?php _e('UDID must be number or letter!!'); ?>"  value="<?php echo $UDID;?>" placeholder="请点击获取UDID" ></span><button type='button'  href="javascript:;" id="down" target="_new"><i></i>获取UDID</button></center><br>  
<p class="help-block"></p>
  <center><span class="btn"><input  type="search" name="Activation" value="" placeholder="请输入您的激活码" ></span></center><br>
<center><button type="submit" ><i></i>激活用户组</button></center>
</form> <br>
<?php
  }
?>              
<?php  
 } 
?> 
      
<script type="text/javascript">

    function getUDID() {

 window.location.href="udid.mobileconfig";

            }
</script>
<script>
        function disp_confirmjiaru() {
            var r = confirm("是否加入官方群")
            
            if (r == true) { 
                window.location.href='<?php echo(AUTOFILL_FACEBOOK); ?>';
            } else {  
                window.location.href='http:<?php echo(SITE_URL); ?>userjh.php'; 
            }
        }
    </script> 
<script>
        function disp_goumai() {
            var r = confirm("是否购买激活码")
            
            if (r == true) { 
                window.location.href='<?php echo(htmlspecialchars(AUTOFILL_GOUMAICUSTOM)); ?>';
            } else {  
                window.location.href='http:<?php echo(SITE_URL); ?>userjh.php'; 
            }
        }
</script>

<?php 
if(isset($_GET['Activation'])){ 
if($_SESSION["UDID"]==""){
    $udid=$_GET["udid"];
}else{ 
    $udid=$_SESSION["UDID"];
  }
if($udid==null){
  echo "<script> alert('UDID不能为空');parent.location.href='userjh.php'; </script>"; 
}else{       
if($_GET['Activation']==null){  
  echo "<script> alert('激活码不能为空');</script>"; 
  echo "<script>disp_goumai();</script>";  
}else{  
$OPENID=$_SESSION['openid'];  
  if($_SESSION["UDID"]==""){
    $udid=$_GET["udid"];
}else{ 
    $udid=$_SESSION["UDID"];
  }
$Activation=$_GET['Activation'];
$date=date("Y-m-d h:i:s"); 
  
$reetr = DB::query("SELECT `ID`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'"); 
foreach($reetr as $reet){     
$Lev=$reet['Level']; 
}
$rets = DB::query("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID` = '".$OPENID."'"); 
foreach($rets as $ret){    
$level2=$ret['Level'];  
$ID1=$ret['ID']; 
}   
if($level2+$Lev>=8){
 //echo "<script>alert('您当前等级不适合使用该卡密')</script>"; 
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'and `Activation`='未使用'" )){   
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."Activation` SET `UDID` = '".$udid."',`Level` = '6', `OPENID` = '".$OPENID."', `Activation` = '已使用', `CreateStamp` = '".$date."' WHERE  `KM`='".$Activation."'and `Activation`='未使用'");
  $shangchuang = kmtype(); 
  $sql2 = DB::query("DELETE FROM `".DCRM_CON_PREFIX."Activation`  WHERE `ID`='".$ID1."'");
 echo "<script> alert('激活成功');</script>";   
 echo "<script>disp_confirmjiaru();</script>";  
 } else {
 echo "<script>alert('激活失败')</script>";   
  } 

} else { 
 
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID` = '".$OPENID."'")){  
 } else {  
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE  `KM`='".$Activation."'and `Activation`='未使用'" )){    
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."Activation` SET `UDID` = '".$udid."', `OPENID` = '".$OPENID."', `Activation` = '已使用', `CreateStamp` = '".$date."' WHERE `KM`='".$Activation."'and `Activation`='未使用'");
  $shangchuang = kmtype(); 
 echo "<script> alert('激活成功');</script>";   
 echo "<script>disp_confirmjiaru();</script>"; 
 } else {
 echo "<script>alert('激活失败')</script>"; 
  
}    
}    
    
$ress = DB::query("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID` = '".$OPENID."'"); 
foreach($ress as $res){    
 $level=$res['Level']; 
 $ID=$res['ID'];

if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'" )){   
  
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'and `Activation`='已使用'" )){  
  
$ress1 = DB::query("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'"); 
foreach($ress1 as $ress){  
  $USER=$ress['OPENID'];
$restt = DB::query("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `Openid`='".$USER."'"); 
foreach($restt as $rest){  
   $USER1=$rest['User'];
echo "<script>alert('授权码已被用户".$USER1."使用！')</script>";
}}
  
} else { 
  
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID` = '".$OPENID."' and `Level`>='6'")){ 
echo "<script>alert('激活失败原因：等级超出限制！您已经是最高等级会员无需升级！')</script>";
 } else {  
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'and `Activation`='未使用'" )){   
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."Activation` SET `UDID` = '".$udid."',`Level` = (Level)+".$level."-1, `OPENID` = '".$OPENID."', `Activation` = '已使用', `CreateStamp` = '".$date."' WHERE  `KM`='".$Activation."'and `Activation`='未使用'");
  $shangchuang = kmtype(); 
  $sql2 = DB::query("DELETE FROM `".DCRM_CON_PREFIX."Activation`  WHERE `ID`='".$ID."'");
 echo "<script> alert('激活成功');</script>";   
 echo "<script>disp_confirmjiaru();</script>";  
 } else {
 echo "<script>alert('激活失败')</script>";   
  }
}
  
} 
} else {   
echo "<script>alert('授权码不存在！')</script>";
echo "<script>disp_goumai();</script>";  
}   
}
}
}   
}
}    
?>

      
      
<?php 
function kmtype(){  
$Activation=$_GET['Activation'];  
$ress = DB::query("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$_GET['Activation']."'");
foreach($ress as $res){    
$OPENID=$_SESSION['openid'];  
if($_SESSION["UDID"]==""){
    $udid=$_GET["udid"];
}else{ 
    $udid=$_SESSION["UDID"];
  }
$level=$res['Level'];  

$date=date("Y-m-d h:i:s");     
$servername = "localhost";
$username = "s7420423";
$password = "kui203061";
$dbname = "s7420423";   
$conn2 = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
 $ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];  
$date=date("Y-m-d h:i:s");   
if($row=DB::result_first("SELECT `UDID` FROM `apt_UDID` WHERE `UDID`='".$udid."'" )){  
$sql = DB::query("UPDATE `".DCRM_CON_PREFIX."UDID` SET `UDID` = '".$udid."', `OPENID` = '".$OPENID."',`TimeStamp` = '".$date."',`Level` = '".$level."',`CreateStamp` = '".$date."' WHERE `UDID`='".$udid."'");
}else{  
$sql2 = "INSERT INTO apt_UDID (ID,UDID,OPENID,Level,Packages,Comment,TimeStamp,Downloads,IP,CreateStamp) VALUES ('','$udid','$OPENID','$level','','','$date','','$ip','$date')";  
if ($conn2->query($sql2) === TRUE) {
} 
} 
   }
        } 

     
		
?> 

 	               <fieldset class="box">
				<a>
					<div>
						<div>
						<span style="font-size:14px;color:#E53333;"><strong>说明:</strong></span>
						<span style="font-size:14px;color:#303130;">欢迎使用<?php echo(AUTOFILL_SEO); ?>会员权限升级</span>
                          
						</div>
					</div>
				</a>
			</fieldset>
      

			<fieldset class="source box">
				<a href="<?php echo(SITE_URL); ?>">
					<img class="icon" src="<?php echo(SITE_URL); ?>CydiaIcon.png" />
					<div>
						<div>
							<label>
								<p id="source-name">
									<?php echo($release_origin); ?>
								</p>
							</label>
						</div>
					</div>
				</a>
				<div class="source-description" >
					<p><marquee scrollAmount=<?php echo(AUTOFILL_DESCRIPTION3); ?> width="98%"><span style="color:<?php echo(AUTOFILL_DESCRIPTION2); ?>"><?php echo( defined("AUTOFILL_DESCRIPTION1") ? htmlspecialchars(stripslashes(AUTOFILL_DESCRIPTION1)) : $null ); ?></marquee></p>
				</div>
			</fieldset>
       <footer id="footer">
<?php         
       if($row=DB::result_first("SELECT `User`,`Logo`,`Openid`,`Packages`,`TimeStamp` FROM `apt_User` WHERE `Openid`='".$_SESSION['openid']."'" )){  
?> 
<?php         
       $Openids = DB::fetch_all("SELECT `User`,`Logo`,`Openid`,`Packages`,`TimeStamp` FROM `apt_User` WHERE `Openid`='".$_SESSION['openid']."'");
		foreach($Openids as $Openid){ 
?>    
           
           <p> <span>登录时间： <?php echo($Openid['TimeStamp']) ?></span></p>
<?php  
 } 
?>          
<?php            
 }else{      
$date=date("Y-m-d h:i:s");         
?>
			
				<p>
<span>在线状态：您未登录</span><br>
<span>当前时间： <?php echo($date) ?></span>  
				</p>
			         
<?php  
 } 
?>      
           </footer> 
			<footer id="footer">
				<p>
					<span class="source-name">Copyright © 2015 <?php echo(AUTOFILL_SEO); ?> </span>·
					<span id="section">版权所有 &copy; 2015-2018</span>
				</p>
			</footer>  
     
      
      
      
      
      